let fs = wps.FileSystem

let prefixPath = wps.Env.GetAppDataPath()
//let prefixPath = 'D://'
let configPath = "llmconfig.json"
let fullConfigPath = prefixPath + "/kingsoft/office6/jsapi/filesystem/" + configPath

const LLM_BASE_URL_KEY = "baseUrl"
const LLM_APIKEY_KEY = "apiKey"
const LLM_MODEL_NAME = "modelName"
const DEFAULT_PROMPT_KEY = "default_prompt_key"
const POLISH_PROMPT_KEY = "polish_prompt_key"
const CON_WRITE_PROMPT_KEY = "con_write_prompt_key"

//设置null为清除key
function setItem(key, value) {
    let json = {}
    if (isExists(fullConfigPath)) {
        let configData = fs.readFileString(configPath)
        json = readStrToJson(configData)
        // if (value == null || !value) {
        //     json.delete(key)
        // } else {
        json[key] = value
        // }
        //移除原文件重新写入
        fs.Remove(configPath)
    } else {
        json[key] = value
    }
    fs.writeFileString(configPath, JSON.stringify(json))
}

function getItem(key) {
    if (isExists(fullConfigPath)) {
        let configData = fs.readFileString(configPath)
        json = readStrToJson(configData)
        return json[key]
    }
}

//判断文件是否存在
function isExists(path) {
    //必须是一个全路径
    return fs.Exists(path)
}

function readStrToJson(text) {
    var jsonObject = JSON.parse(text);
    return jsonObject
}

export default {
    setItem,
    getItem,
    LLM_BASE_URL_KEY,
    LLM_APIKEY_KEY,
    LLM_MODEL_NAME,
    DEFAULT_PROMPT_KEY,
    POLISH_PROMPT_KEY
}